package com.freesky.provider.order.util;

import com.freesky.common.exception.EMallException;
import com.freesky.common.dao.entity.Order;

import java.util.Date;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 15:46 2018/12/5
 * @description:
 */
public class OrderUtil {
    /**
     * 判断订单是否超时未支付
     */
    public static String judgeOrder(Order order){

        String result=null;
        if(order.getStatus()==0){
            //判断是否已超1天
            long diff=System.currentTimeMillis()-order.getCreateTime().getTime();
            long days = diff / (1000 * 60 * 60 * 24);
            if(days>=1){
                //设置失效
                order.setStatus(5);
                order.setCloseTime(new Date());
                boolean update = order.updateById();
                if(!update){
                    throw new EMallException("更新订单失效失败");
                }
            }else {
                //返回到期时间
                long time=order.getCreateTime().getTime()+1000 * 60 * 60 * 24;
                result= String.valueOf(time);
            }
        }
        return result;
    }
}
